<?php
namespace Home\Controller;

use Think\Controller;
use Admin\Model\CustpModel;

class IndexController extends Controller
{

    public function index()
    {
        $this->display();
    }

    public function verify()
    {
        $config = array(
            'fontSize' => 20, // 验证码字体大小
            'length' => 4, // 验证码位数
            'imageH' => 35, // 验证码高度
            'useNoise' => true, // 关闭验证码杂点
                                // 'fontttf' => '1.ttf',
                                // 'codeSet' => '0123456789',
                                // 'useZh' => true,
            'useImgBg' => true
        );
        $Verify = new \Think\Verify();
        $Verify->length = 4;
        $Verify->fontttf = 'SIMKAI.TTF';
        $Verify->useZh = true;
        $Verify->entry();
        // $verify = new \Think\Verify($config);
        // $verify->entry();
    }

    public function login()
    {
        $UM = new CustpModel();
        $FM = $UM->create();
        if (! $FM) {
            $this->validateMess = $UM->getError();
        } else {
            $verify = new \Think\Verify();
            $isverify = $verify->check($_POST['captcha']);
            if (! $isverify) {
                $this->validateMess = '验证码错误！';
            } else {
                $rs = loginqt($FM);
                if (! ($rs['status'])) {
                    $this->validateMess = $rs['data'];
                } else {
                    $this->success('登录成功，正在跳转...', U('/Index/index'), 1);
                }
            }
        }
        $this->display();
    }

    public function reg()
    {
        $UM = new CustpModel();
        $data = $UM->create();
        if (! $data) {
            $UM->getError();
        } else {
            $add = $UM->add($data);
            if (add) {
                $this->success('注册成功，请登陆', U('Index/login'));
            } else {
                $this->error('注册失败');
            }
        }
        $this->display();
    }

    public function zx()
    {
        if (session('uid')) {
            $this->success('请保持手机畅通，稍候工作人员会联系您！', U('Index/index'));
            //数据表增加一个字段记录
        } else {
            $this->success('请登陆后再试', U('Index/login'));
        }
    }

    public function dg()
    {
        if (session('uid')) {
            $this->success('请保持手机畅通，稍候工作人员会联系您确认信息！', U('Index/index'));
        } else {
            $this->success('请登陆后再试', U('Index/login'));
        }
    }

    public function gz()
    {
        if (session('uid')) {
            $this->success('关注成功！', U('Index/index'));
        } else {
            $this->success('请登陆后再试', U('Index/login'));
        }
    }

    public function logout()
    {
        session_unset();
        session_destroy();
        $this->success('退出成功！', U('Index/index'));
    }
}